import React from 'react';
import { connect } from 'umi';

import NumberFormatter from '@/pages/SalaryManage/components/NumberFormatter';
import EmptyPlaceHolder from '@/pages/SalaryManage/components/EmptyPlaceHolder';

import salaryStyle from '@/pages/SalaryManage/salaryManage.less';

/*
 * 获取【累计预扣预缴应纳税所得额】描述信息
 * @example ≤36,000.00, 36,000.00~144,000.00, >960,000.00
 * @param record.taxStartAmt
 * @param record.taxEndAmt
 * @returns {string}
 */
const TaxAmtDescription = ({ record, decimalPlaces }) => {
    const taxStartAmt = record?.taxStartAmt;
    const taxEndAmt = record?.taxEndAmt;
    const formatStartAmt = (
        <NumberFormatter
            value={taxStartAmt}
            decimalPlaces={decimalPlaces}
            thousandsSeparator=","
            className={salaryStyle.currency}
        />
    );
    const formatEndAmt = (
        <NumberFormatter
            value={taxEndAmt}
            decimalPlaces={decimalPlaces}
            thousandsSeparator=","
            className={salaryStyle.currency}
        />
    );

    if (taxStartAmt != null && taxEndAmt != null) {
        return (
            <>
                {formatStartAmt}~{formatEndAmt}
            </>
        );
    }

    if (taxStartAmt && taxEndAmt == null) {
        return <>&gt;{formatStartAmt}</>;
    }

    if (taxStartAmt == null && taxEndAmt) {
        return <>≤{formatEndAmt}</>;
    }

    return <EmptyPlaceHolder />;
};

TaxAmtDescription.displayName = 'TaxAmtDescription';

/*
 * 获取【累计预扣预缴应纳税所得额】描述信息
 * decimalPlaces来源于后台配置（来源于models中finance.js中的baseSetting.scale）
 * @param record
 * @returns {string}
 */
const TaxAmtSettingDescription = connect(({ finance }) => ({
    decimalPlaces: finance.baseSetting?.scale
}))(TaxAmtDescription);
TaxAmtSettingDescription.displayName = 'TaxAmtSettingDescription';

export { TaxAmtDescription, TaxAmtSettingDescription };
